/**
 * @author	barbarosalcin
 * @desc	user js
 * @version	$Id: 20110222
 */


var _ajax_status = $("#tk-ajax-status");
var _ajax_status_title = $("#tk-ajax-status-title");

function check_json(data) {
	if (_json_checked)
		return true;
	try {
		var _resp = (typeof (data) == 'object') ? data : $.parseJSON(data);
	} catch (e) {
		_ajax_status_title.removeClass('sprite-idle').removeClass('sprite-wait').removeClass('sprite-exclamation').addClass('sprite-error');
		_ajax_status.html("Hata! Sunucudan gelen veri işlenemedi.");
		return false;
	}
	if (_resp == null) {
		_ajax_status_title.removeClass('sprite-idle').removeClass('sprite-wait').removeClass('sprite-error').addClass('sprite-exclamation');
		_ajax_status.html("Boş veri.");
		return false;
	}

	if (_resp.xhr_status == 0) {

		_ajax_status_title.removeClass('sprite-idle').removeClass('sprite-wait').removeClass('sprite-exclamation').addClass('sprite-error');
		if (_resp.message == null) {
			_ajax_status.html('Tanımsız hata.');
		} else {
			_ajax_status.html(_resp.message);
		}
		return false;
	} else {
		_ajax_status_title.removeClass('sprite-error').removeClass('sprite-wait').removeClass('sprite-exclamation').addClass('sprite-idle');
		if (_resp.message == null) {
			_ajax_status.html('Uygun');
		} else {
			_ajax_status.html(_resp.message);
		}
		_json_checked = true;
		return true;
	}
}

function openModal()
{
    $("#modal_message").dialog({
        modal: true,
        autoOpen: true,
        height: 300,
        width: 300,
        resizable: false,
        draggable: false,
        buttons: [{
                      html:'<span class="left ui-icon ui-icon-closethick"></span>&nbsp;Kapat',
                      click: function(){
                          $(this).dialog("close").dialog("destroy");
                      }
                  }]
    });		
}
try {

	jQuery(function($) {
		
		$.fn.extend({
		    disableSelection : function() {
		            this.each(function() {
		                    this.onselectstart = function() { return false; };
		                    this.unselectable = "on";
		                    $(this).css('-moz-user-select', 'none');
		            });
		            return this;
		    },
		    slideFadeToggle : function(speed, easing, callback) {
		    	return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);

		    },
		    serializeObject : function()
		    {
				   var o = {};
				   var a = this.serializeArray();
				   $.each(a, function() {
				       if (o[this.name]) {
				           if (!o[this.name].push) {
				               o[this.name] = [o[this.name]];
				           }
				           o[this.name].push(this.value || '');
				       } else {
				           o[this.name] = this.value || '';
				       }
				   });
				   return o;  	
		    }
		});
		
		$.warnIE6();

		$.preloadCssImages();

		if (_google_analytics != "") {
			$.googleanalytics({
				"UA" : _google_analytics,
				"setAllowLinker" : true
			});
		}

		$.ajaxSetup({
			timeout : 5000,
			error : function(event, request, settings) {
				return false;
			}
		});

		/* Insert JS here */


		
		/* Insert JS here */
		
		$("#toTop").scrollToTop({
			speed : 500,
			start : _scrollstart
		});
		
		$("img").error(function() {
			$(this).hide();
		});

		$(window).error(function() {
			return true;
		});
		
		$('.button,.button3d').disableSelection();


		$("#tk-ajax-status-div").ajaxSend(function(e, xhr, settings) {
			$("#tk-ajax-status-title").removeClass('sprite-idle').removeClass('sprite-error').removeClass('sprite-exclamation').addClass('sprite-wait');
			$("#tk-ajax-status").html('Bekleyiniz.. <img src="' + _templatePath + 'images/ajax-loader.gif" alt="" /> ');
		});

		$("#tk-ajax-status-div").ajaxError(function(e, xhr, settings) {
			var _ajax_status = $("#tk-ajax-status");
			var _ajax_status_title = $("#tk-ajax-status-title");
			if (settings.dataType == 'json') {
				try {
					var _resp = JSON.parse(xhr.responseText);
				} catch (e) {
					_ajax_status_title.removeClass('sprite-idle').removeClass('sprite-wait').removeClass('sprite-exclamation').addClass('sprite-error');
					_ajax_status.html("Sunucudan gelen veri işlenemedi.");
					return false;
				}
				if (_resp == null) {
					_ajax_status_title.removeClass('sprite-idle').removeClass('sprite-wait').removeClass('sprite-error').addClass('sprite-exclamation');
					_ajax_status.html("Boş veri.");
					return false;
				}
				if (_resp.message == '') {
					_ajax_status_title.removeClass('sprite-idle').removeClass('sprite-wait').removeClass('sprite-exclamation').addClass('sprite-error');
					_ajax_status.html('Ön tanımsız hata.');
				} else {
					_ajax_status_title.removeClass('sprite-idle').removeClass('sprite-wait').removeClass('sprite-exclamation').addClass('sprite-error');
					_ajax_status.html(_resp.message);
				}
			} else {
				_ajax_status_title.removeClass('sprite-idle').removeClass('sprite-wait').removeClass('sprite-exclamation').addClass('sprite-error');
				_ajax_status.html("Hata! Sunucudan gelen veri işlenemedi.");
			}
		});

		$("#tk-ajax-status-div").ajaxComplete(function(e, xhr, settings) {
			var _ajax_status = $("#tk-ajax-status");
			var _ajax_status_title = $("#tk-ajax-status-title");

			if (settings.dataType == 'json') {
				if (!_json_checked) {
					check_json(xhr.responseText);
				}

			} else {

				try {
					var _resp = $.parseJSON(xhr.responseText);
					if (_resp.xhr_status == 0) {
						_ajax_status_title.removeClass('sprite-idle').removeClass('sprite-wait').removeClass('sprite-exclamation').addClass('sprite-error');
						if (_resp.message == null) {
							_ajax_status.html('Tanımsız hata.');
						} else {
							_ajax_status.html(_resp.message);
						}
						return false;
					}
				} catch (e) {
					_ajax_status.html('Uygun');
				}
			}
			_json_checked = false;
		});
		
	});
	$('.preloading').fadeOut(500,function(){
		$('.preloaded').css({"display":"none"}).removeClass('display-hide').show();
	});

}

catch (err) {
	alert(err.toString());
};